<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>菜单管理</title>
<script src="${ctx}/static/js/selectWin/meetingRoomSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script src="${ctx}/static/js/selectWin/userSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<link href="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/themes/default/css/ueditor.css" rel="stylesheet">
<script type="text/javascript" src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/ueditor.config.js"></script>
<script type="text/javascript" src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/ueditor.all.js"></script>
<script type="text/javascript" src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="${ctx}/jeasyui-extensions/jeasyui-extensions/jquery-easyui-ueditor/jquery.ueditor.js"></script>
<script type="text/javascript">
	var grid;
	var rowT;
	$(function() {
		grid = $("#grid").datagrid($.extend(datagridOption, {
			title : "会议管理",
			fitColumns : true,
			url : "${ctx}/basic/mrUseRecode/dataGrid",
			columns : [ [ {
				field : 'id',
				checkbox : true
			}, {
				field : 'meetingSubject',
				title : '会议主题',
				width : 80,
				sortable : true
			}, {
				field : 'meetingRoom',
				title : '会议室名称',
				width : 40,
				sortable : true,
				formatter : fmt_emp3
			}, {
				field : 'startTime',
				title : '会议起始时间',
				width : 80,
				sortable : true
			}, {
				field : 'endTime',
				title : '会议结束时间',
				width : 80,
				sortable : true
			}, {
				field : 'meetingStaff',
				title : '与会人员',
				width : 40,
				formatter : fmt_emp1
			}, {
				field : 'meetingSummary',
				title : '会议纪要',
				width : 40,
				formatter : fmt_emp2
			} ] ],
			onClickCell : function(rowIndex, field, value) {
				rowT = func_page();
				if (field == "meetingStaff") {
					//showAlert(rowT[rowIndex].id);
					$("#dlg1").dialog("open").dialog("setTitle", "查看会议--[" + rowT[rowIndex].meetingSubject + "]的与会人员");
					$("#meetingStaffShow").val(rowT[rowIndex].meetingStaff);
				} else if (field == "meetingSummary") {
					if (value == null) {
						$("#dlg2").dialog("open").dialog("setTitle", "书写会议--[" + rowT[rowIndex].meetingSubject + "]的会议纪要");
						$("#fm1").form("clear");
						$("#mid").val(rowT[rowIndex].id);
					} else {
						$("#dlg2").dialog("open").dialog("setTitle", "查看会议--[" + rowT[rowIndex].meetingSubject + "]的会议纪要");
						$("#fm1").form("clear");
						$("#meetingSummaryShow").ueditor("setValue", rowT[rowIndex].meetingSummary);
						$("#mid").val(rowT[rowIndex].id);
					}
				}
			}
		}));
		$("#grid").datagrid('enableFilter', [ {
			field : 'meetingRoom',
			searchField : 'meetingRoom.mrName'
		}, {
			field : 'startTime',
			type : 'datebox',
			javaType : 'D',
			op : [ 'EQ', 'NEQ', 'GT', 'LT', 'GTE', 'LTE', 'ISNULL', 'NOTNULL' ]
		}, {
			field : 'endTime',
			type : 'datebox',
			javaType : 'D',
			op : [ 'EQ', 'NEQ', 'GT', 'LT', 'GTE', 'LTE', 'ISNULL', 'NOTNULL' ]
		} ]);
		$meetingRoomSelector = $("#meetingRoom").comboselector(meetingRoomSelectOpts);
		$("#btn-delete").click(function() {
			multiDeleteDataGrid($("#grid"), "${ctx}/basic/mrUseRecode/multiDelete");
		});
		$("#excelExport").click(function() {
			var url = "${ctx}/basic/mrUseRecode/excelExport?" + $.param($("#grid").datagrid('options').queryParams);
			if ($("#grid").datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($("#grid").datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		$("#userSelector").click(function() {
			$.easyui.showGridSelector($.extend(userSelectOpts, {
				multiple : true,
				singleSelect : false,
				idField : "trueName",
				onEnter : function(val) {
					var str = "";
					if (val && val.length > 0) {
						for (var i = 0; i < val.length; i++) {
							if (i != (val.length - 1)) {
								str += val[i].trueName + ",";
							} else {
								str += val[i].trueName;
							}
						}
						$("#meetingStaff").val(str);
					}
				}
			}));
		});
	});

	function func_page() {
		return $("#grid").datagrid("getRows");
	}
	function fun_user_add() {
		$("#dlg").dialog("open").dialog("setTitle", "新增会议");
		$("#fm").form("clear");
	}

	function fun_user_edit() {
		var row = $("#grid").datagrid("getSelected");
		if (row == null) {
			showAlert("您未选择任何记录!");
		} else {
			$("#dlg").dialog("open").dialog("setTitle", "编辑会议--[" + row.meetingSubject + "]");
			$("#fm").form("clear").form("load", row);
			$("#meetingRoom").comboselector("setValue", row.meetingRoom.id).comboselector("setText", row.meetingRoom.mrName);
		}
	}

	function fun_mrUseRecode_save() {
		var i = 0;
		if ($("#meetingRoom").comboselector("getValue") == null) {
			$.messager.show({
				msg : "您未选指定会议室！",
				icon : "warning",
				position : "bottomRight"
			});
			i = 1;
		}
		if ($("#meetingStaff").val() == null) {
			$.messager.show({
				msg : "您未输入与会人员！",
				icon : "warning",
				position : "bottomRight"
			});
			i = 1;
		}
		if ($("#meetingSubject").val() == null) {
			$.messager.show({
				msg : "您未输入会议主题！",
				icon : "warning",
				position : "bottomRight"
			});
			i = 1;
		}
		if ($("#startTime").val() == null) {
			$.messager.show({
				msg : "您未输入会议起始时间！",
				icon : "warning",
				position : "bottomRight"
			});
			i = 1;
		}
		if ($("#endTime").val() == null) {
			$.messager.show({
				msg : "您未输入会议结束时间！",
				icon : "warning",
				position : "bottomRight"
			});
			i = 1;
		}
		if (i == 0) {
			$("#fm").form("submit", {
				url : "${ctx}/basic/mrUseRecode/update",
				success : function(data) {
					if (data.success) {
						$("#dlg").dialog("close");
						$("#grid").datagrid("load");
					}
					showInfo(data.msg);
				}
			});
		}
	}

	function fun_meetingSummary_save() {
		$("#fm1").form("submit", {
			url : "${ctx}/basic/mrUseRecode/update",
			success : function(data) {
				if (data.success) {
					$("#dlg2").dialog("close");
					$("#grid").datagrid("load");
				}
				showInfo(data.msg);
			}
		});
	}

	//查询条件
	function fnd_search() {
		$("#grid").datagrid('load', {
			search_LIKE_meetingSubject : $("#search_LIKE_meetingSubject").val()
		});
	}

	//formatter
	function fmt_emp1() {
		return '<span style="color:blue">查看与会人员</span>';
	}

	function fmt_emp2(val, row) {
		if (val == null) {
			return '<span style="color:blue" onclick="func_">书写会议纪要</span>';
		} else {
			return '<span style="color:blue">查看会议纪要</span>';
		}
	}
	function fmt_emp3(val, row) {
		if (val == null) {
			return '<span style="color:blue">暂无会议室安排</span>';
		} else {
			return val.mrName;
		}
	}
</script>
</head>
<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
		<div id="tt">
			<!-- 查询条件 -->
			<!-- 功能按钮 -->
			<shiro:hasPermission name="mrUseRecode:update">
				<a id="btn-add" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain: true" onclick="fun_user_add()">新增会议</a>
				<a id="btn-edit" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-hamburg-pencil',plain: true" onclick="fun_user_edit()">修改</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="mrUseRecode:delete">
				<a id="btn-delete" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-hamburg-busy',plain: true">删除</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="mrUseRecode:export">
				<a id="excelExport" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-page-excel'">Excel导出</a>
			</shiro:hasPermission>
		</div>
		<shiro:hasPermission name="mrUseRecode:update">
			<div id="dlg" class="easyui-dialog" style="width: 400px; height: 400px; padding: 10px 20px" closed="true"
				data-options="iconCls:'icon-save',resizable:true,modal:true, buttons:[
                    { text: '保存', iconCls: 'icon-ok', handler: function () { fun_mrUseRecode_save(); } },
                    { text: '取消', iconCls:'icon-cancel', handler: function () { $('#dlg').dialog('close'); } }
                ],closed:true">
				<form id="fm" method="post">
					<input id="id" type="hidden" name="id" />
					<table id="tbl">
						<tr>
							<td width="80px"><label>会议主题:</label></td>
							<td><input id="meetingSubject" name="meetingSubject" class="easyui-validatebox" data-options="required:true" /></td>
						</tr>
						<tr>
							<td><label>会议室:</label></td>
							<td><input id="meetingRoom" name="meetingRoom" data-options="required:true"></td>
						</tr>
						<tr>
							<td><label>会议起始时间:</label></td>
							<td><input id="startTime" name="startTime" data-options="required:true" class="easyui-my97" datefmt="yyyy-MM-dd HH:mm"
								style="margin: 2px; width: 178px;" data-options="required:true" /></td>
						</tr>
						<tr>
							<td><label>会议结束时间:</label></td>
							<td><input id="endTime" name="endTime" data-options="required:true" class="easyui-my97" datefmt="yyyy-MM-dd HH:mm"
								style="margin: 2px; width: 178px;" data-options="required:true"></td>
						</tr>

						<tr>
							<td><label>与会人员:</label><a id="userSelector" class="easyui-linkbutton easyui-tooltip"
								data-options="plain: true, iconCls: 'icon-metro-search',content:'关联员工'"></a></td>
							<td><textarea id="meetingStaff" name="meetingStaff" rows="8px" cols="20px"></textarea></td>
						</tr>
					</table>
				</form>
			</div>
		</shiro:hasPermission>
		<div id="dlg1" class="easyui-dialog" style="width: 300px; height: 200px; padding: 10px 20px" closed="true"
			data-options="iconCls:'icon-save',resizable:true,modal:true, buttons:[
                    { text: '取消', iconCls:'icon-cancel', handler: function () { $('#dlg1').dialog('close'); } }
                ],closed:true">
			<textarea id="meetingStaffShow" cols="28" rows="6" readonly></textarea>
		</div>
		<div id="dlg2" class="easyui-dialog" style="width: 840px; height: 520px; padding: 10px 20px" closed="true"
			data-options="iconCls:'icon-save',resizable:true,modal:true, buttons:[
				{ text: '保存', iconCls: 'icon-ok', handler: function () { fun_meetingSummary_save(); } },
                    { text: '取消', iconCls:'icon-cancel', handler: function () { $('#dlg2').dialog('close'); } }
                ],closed:true">
			<form id="fm1" method="post">
				<input id="mid" type="hidden" name="id" />
				<textarea id="meetingSummaryShow" class="easyui-ueditor" name="meetingSummary"
					data-options=" required: true, height: 420,width:780, value: '',
                              template: 'full', codeMirrorJsUrl: false, codeMirrorCssUrl: false"></textarea>
			</form>
		</div>
	</div>
</body>
</html>
